package com.upcontrol.uartagent.core;

import android.content.Context;

import com.upcontrol.uartagent.core.inter.DataReceive;
import com.upcontrol.uartagent.core.inter.IConnector;
import com.usb2uartagent.IUARTConnectorHelper;

/**
 * Copyright (c) 2017, SuZhou CsjBot. All Rights Reserved.
 * www.csjbot.com
 * <p>
 * Created by 浦耀宗 at 2017/02/09 0009-14:06.
 * Email: puyz@csjbot.com
 */
public class UartConnectHelper implements IUARTConnectorHelper {
    private IConnector mUartConnect;

    @Override
    public void onDataRecevie(byte[] data) {
        ClientManager.getInstance().onReceive(data);
    }

    @Override
    public void setDataReceive(DataReceive receive) {
        mUartConnect.setDataReceive(receive);
    }

    @Override
    public int init(Context context, String device, int speed) {
        mUartConnect = new UartConnectRK3288();
//        return -1;
        return mUartConnect.connect(device, speed);
    }

    @Override
    public int send(byte[] data) {
//        return -1;
        return mUartConnect.sendData(data);
    }

    @Override
    public void destroy() {
        mUartConnect.destroy();
        mUartConnect = null;
    }
}
